package com.tarena.lbs.business.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.business.pojo.param.BusinessParam;
import com.tarena.lbs.business.pojo.param.BusinessStatusParam;
import com.tarena.lbs.business.pojo.query.BusinessQuery;
import com.tarena.lbs.business.pojo.vo.BusinessStoreVO;
import com.tarena.lbs.business.pojo.vo.BusinessVO;
import com.tarena.lbs.business.servcie.BusinessService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@Tag(name = "商家相关功能接口")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    @Operation(summary = "查询商家列表")
    @GetMapping("/admin/basic/business/info/list")
    public Result<PageResult<BusinessVO>> pageList(BusinessQuery query) throws BusinessException {
        log.info("查询商家列表，入参:{}", query);
        PageResult<BusinessVO> pageResult = businessService.pageList(query);
        return new Result<>(pageResult);
    }

    @Operation(summary = "新增商家")
    @PostMapping("/admin/basic/business/info/save")
    public Result<Void> save(@RequestBody BusinessParam param) throws BusinessException {
        businessService.save(param);
        return Result.success();
    }

    @Operation(summary = "更新商家信息")
    @PutMapping("/admin/basic/business/info/update")
    public Result<Void> update(@RequestBody BusinessParam param) throws BusinessException {
        businessService.update(param);
        return Result.success();
    }

    @Operation(summary = "更新审批状态")
    @PutMapping("/admin/basic/business/info/updateStatus")
    public Result<Void> updateStatus(@RequestBody BusinessStatusParam param) throws BusinessException {
        businessService.updateStatus(param);
        return Result.success();
    }

    @Operation(summary = "删除商家")
    @DeleteMapping("/admin/basic/business/info/delete/{id}")
    public Result<Void> delete(@PathVariable("id") Integer id) throws BusinessException {
        businessService.delete(id);
        return Result.success();
    }

    @Operation(summary = "商家详情")
    @GetMapping("/basic/business/info/detail/{id}")
    public Result<BusinessStoreVO> busiStoreDetail(@PathVariable("id") Integer businessId) throws BusinessException {
        BusinessStoreVO detail = businessService.detail(businessId);
        return new Result<>(detail);
    }
}